﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sec_scan指纹识别系统
{
    /// <summary>
    /// 读取数据库
    /// </summary>
    public class Sec_scanDbOpen
    {
        /// <summary>
        /// 读取数据库指纹信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static string InfoScan(string info)
        {
            Sec_scanDbOpenApi.SecPath = new StringBuilder();
            Sec_scanDbOpenApi.SecKey = new StringBuilder();
            Sec_scanDbOpenApi.SecName = new StringBuilder();
            Sec_scanDbOpenApi.SecVersion = new StringBuilder();
            Sec_scanDbOpenApi.SecType = new StringBuilder();
            string sqlinfo = "data source=Sec_infoscan.db";
            SQLiteConnection dataConn = new SQLiteConnection(sqlinfo);
            dataConn.Open();
            try
            {
                if (dataConn.State == ConnectionState.Open)
                {
                    string sql = "SELECT ID, fingepath, fingekey, fingename, fingewafname, fingewafkey, fingewafform, fingeip, systemname, systemversion, systemtype FROM Sec_form";
                    SQLiteCommand command = new SQLiteCommand(sql, dataConn);
                    using (SQLiteDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (dr.Read())
                        {
                            string s1 = dr["fingepath"].ToString();
                            string s2 = dr["fingekey"].ToString();
                            string s3 = dr["systemname"].ToString();
                            string s4 = dr["systemversion"].ToString();
                            string s5 = dr["systemtype"].ToString();
                            Sec_scanDbOpenApi.SecPath.Append(s1.ToString());//获取指纹识别路径
                            Sec_scanDbOpenApi.SecKey.Append(s2.ToString());//指纹识别关键特征
                            Sec_scanDbOpenApi.SecName.Append(s3.ToString() + "\r\n");//指纹识别名称
                            Sec_scanDbOpenApi.SecVersion.Append(s4.ToString());//指纹识别版本
                            Sec_scanDbOpenApi.SecType.Append(s5.ToString());//指纹类型
                        }
                    }
                }
                else
                {
                    string error = "数据库无法打开！";
                    Sec_scanDbOpenApi.BdOpenError = error.ToString();//数据库无法打开的情况下执行
                }
            }
            catch (Exception ex)
            {
                Sec_scanDbOpenApi.OpExOptions.Append(ex.ToString());//获取整体的错误状态
            }
            return info;
        }
    }
}
